<template>
  <div>

    <p>
        {{fa_data.name}} 
    </p><br><br><br>
        <div v-for="i in data" :key="i.id">
        <p v-if="i.che == 0">{{i.text}}--------- <button @click="che(i.id)">撤回</button></p>
        <p v-else>该用户已撤回一条信息</p>
    </div>
    <br><br>

    <p>
        输入内容：<input type="text" v-model="text">
        <button @click="jiao">发送</button> 
    </p>
  </div>
  
</template>

<script>
import axios from 'axios'
export default {
data() {
    return {
        mid:this.$route.query.id,
        fa_data:[],
        text:'',
        uid:localStorage.getItem('uid'),
        data:[],
    }
},
created(){
    axios.get('http://127.0.0.1:8000/z/cehui/?mid='+this.mid).then(resp=>{
        console.log(resp.data)
        this.fa_data = resp.data
        
    }),
    this.xiao()
},
methods:{
    jiao(){
            axios({
                url:'http://127.0.0.1:8000/z/cehui/',
                method:'post',
                data:{'uid':this.uid,'text':this.text}
            }).then(res =>{
                console.log(res.data)
                this.$router.go(0)
            })
        },
    che(id){
            axios({
                url :'http://127.0.0.1:8000/z/cehui/',
                method:'put',
                data:{'uid':this.uid,'id':id}
            }).then(res =>{
                console.log(res.data)
                alert(res.data.msg)
                this.$router.go(0)
            })
        },
    xiao(){
            axios.get('http://127.0.0.1:8000/z/xiaoxi/').then(resp=>{
                console.log(resp.data)
                this.data = resp.data
            }).catch(err=>{
                console.log(err)
            })
        }
},
}
</script>

<style>

</style>